package org.gangcai.mac.shop.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.SPUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.bumptech.glide.Glide;

import org.gangcai.mac.shop.R;
import org.gangcai.mac.shop.bean.CommonResonseBean;
import org.gangcai.mac.shop.bean.ConfirmOrderBean;
import org.gangcai.mac.shop.common.MultiStatusActivity;
import org.gangcai.mac.shop.constants.Constant;
import org.gangcai.mac.shop.manager.RetrofitManager;
import org.gangcai.mac.shop.oberver.CommonObserver;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import io.reactivex.android.schedulers.AndroidSchedulers;

public class OrderCompleteActivity extends MultiStatusActivity {

    @BindView(R.id.timeTips)
    TextView timeTips;
    @BindView(R.id.time)
    TextView time;
    @BindView(R.id.lookOrder)
    Button lookOrder;
    @BindView(R.id.reSale)
    Button reSale;
    @BindView(R.id.goodImage)
    ImageView goodImage;
    @BindView(R.id.goodTitle)
    TextView goodTitle;
    @BindView(R.id.goodMoney)
    TextView goodMoney;
    @BindView(R.id.yiyuqi)
    TextView yiyuqi;
    private ConfirmOrderBean value;


    private String money;
    private String order_id;
    private String gid;
    private boolean alipay;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initTitleBarView(titlebar, "订单完成");
        ButterKnife.bind(this);
        Bundle extras = getIntent().getExtras();
        value = extras.getParcelable("value");
        alipay = extras.getBoolean("alipay");

        money = value.getBack_money();
        gid = value.getGid();
        order_id = value.getOrderId();


        initView();
    }

    private void initView() {

        time.setVisibility(View.INVISIBLE);
        timeTips.setTextColor(getResources().getColor(R.color.textColorDark));
        yiyuqi.setVisibility(View.INVISIBLE);

        timeTips.setText("三方回收价 : ¥" + value.getBack_money());
        goodTitle.setText(value.getGoods_name());
        goodMoney.setText("¥" + value.getMoney());
        Glide.with(this).load(Constant.IMAGE_PATH + value.getImg()).into(goodImage);
        if (alipay) {
            reSale.setVisibility(View.GONE);
        }

    }

    @Override
    public int getContentView() {
        return R.layout.activity_order_complete;
    }

    @OnClick({R.id.lookOrder, R.id.reSale})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.lookOrder:
                //查看订单
                BillDetailActivity.open(order_id, "订单详情", alipay ? "2" : "1");

                break;
            case R.id.reSale:
                //请求转卖
                ShopReSaleActivity.open(value.getGoods_name(), money, order_id, gid, "", value.getImg());
                break;
        }
        finish();
    }

    private void submitSale() {

    }

    public static void open(ConfirmOrderBean mValue, boolean alipay) {
        Bundle bundle = new Bundle();
        bundle.putParcelable("value", mValue);
        bundle.putBoolean("alipay", alipay);
        ActivityUtils.startActivity(bundle, OrderCompleteActivity.class);

    }
}
